﻿Namespace Util

    Public Class PasswordGenerator

        Protected Shared _gerenteSenha As GerenteDeSenha


        <Obsolete("Não será oferido suporte futuro a essa funcionalidade. Utilizar o IAutenticacaoServico.GerarSenhaForte()")> _
        Public Shared Function GeneratePassword(ByVal length As Integer) As String

            'Static rand As New Random
            'Dim password As New System.Text.StringBuilder(length)

            'For i As Integer = 1 To length
            '    Dim charIndex As Integer
            '    ' allow only digits and letters 
            '    Do
            '        charIndex = rand.Next(48, 123)
            '    Loop Until (charIndex >= 48 AndAlso charIndex <= 57) _
            '      OrElse (charIndex >= 65 AndAlso charIndex <= 90) _
            '      OrElse (charIndex >= 97 AndAlso charIndex <= 122)
            '    ' add the random char to the password being built 
            '    password.Append(Convert.ToChar(charIndex))
            'Next
            'Return password.ToString()

            If PasswordGenerator._gerenteSenha Is Nothing Then
                PasswordGenerator._gerenteSenha = New GerenteDeSenha
                With PasswordGenerator._gerenteSenha
                    .ExigeLetras = True
                    .ExigeMaiusculas = True
                    .ExigeSimbolos = True
                    .ExigeNumeros = True
                    .NotaMinimaParaContinuar = 4

                    .NotaTamanhoMinimo = 1
                    .NotaExisteNumero = 1
                    .NotaExisteMinuscula = 1
                    .NotaExisteMaiuscula = 1
                    .NotaExisteCaracteresNaSenha = 1
                    .MinimoCaracteresSenha = length
                End With
            End If

            Return PasswordGenerator._gerenteSenha.GerarSenhaForte()

        End Function

    End Class

End Namespace